<template>
  <div>
    <div>
      <div class="container">
        <div class="form">
          <h2>注册</h2>
          <form>
            <div class="inputBox">
              <input type="text" placeholder="用户名" v-model="user.realName">
            </div>
            <div class="inputBox">
              <input type="text" placeholder="账号" v-model="user.userAccount">
            </div>
            <div class="inputBox">
              <input type="password" placeholder="密码" v-model="user.password">
            </div>
            <div class="inputBox">
              <input type="password" placeholder="确认密码" v-model="user.checkPassword">
            </div>
            <div class="inputBox" id="checkBox">
              <input type="button" value="注册" @click="doRegister">
              <input type="button" value="返回" @click="returnLogin">
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import http from "@/util/request";

export default {
  name: "Register",
  data(){
    return {
      user: {
        userAccount: '',
        password: '',
        checkPassword: '',
        realName: ''
      }
    }
  },
  methods: {
    doRegister(){
      http.post('/register',this.user).then(response=>{
        if (response.data){
          this.$router.push('/');
        }else {
          alert(response.data);
        }
      });
    },
    returnLogin(){
      this.$router.push("login");
    }
  }
}
</script>

<style scoped>
#checkBox input{
  margin:20px 0 0 30px;
}
</style>
